package com.lin.fengxiu.service;

import com.lin.fengxiu.model.Category;
import com.lin.fengxiu.repository.CategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CategoryService
 * @Description TODO
 * @Author wushaopei
 * @Date 2021/3/17 6:34
 * @Version 1.0
 */
@Service
public class CategoryService {

    @Autowired
    private CategoryRepository categoryRepository;

    public Map<Integer,List<Category>> getAll(){
        // isRoot 为true 说明为一级分类，反之为二级或以下的分类
        List<Category> roots = categoryRepository.findAllByIsRootOrderByIndexAsc(true);
        List<Category> subs = categoryRepository.findAllByIsRootOrderByIndexAsc(false);
        Map<Integer,List<Category>> categories = new HashMap();
        categories.put(1,roots);
        categories.put(2,subs);
        return categories;
    }

}
